﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using LitJson;

[AddComponentMenu("PUEX/Affector/Rotation/DragRotationSpeedOverLifetime")]
public class PUEXDragRotationSpeedOverLifetimeAffector : PUEXAffector {

	#region - Editable property
	public PUEXDynamicAttribute dragRate;
	#endregion
	
	#region - Lifecycle
	public PUEXDragRotationSpeedOverLifetimeAffector ()
	{
		dragRate = PUEXDynamicAttribute.GenerateFixed(0.5f);
	}
	#endregion
	
	#region - Update
	public override void update (float dt, PUEXParticle particle)
	{
		particle.rotationSpeed += particle.rotationSpeed * -dragRate.getValue (particle.timeFraction) * dt;
	}
	#endregion

	#region - Param property
	public override void updateParams (PUEXParticleSystem system)
	{
		dragRate.parameterize (system);
	}
	#endregion

	#region - Serialization
	public override JsonData save (JsonData emitterData, JsonData systemData)
	{
		JsonData ret = base.save (emitterData, systemData);

		ret ["drag_rate"] = PUEXUtils.serializeDynamicAttribute(dragRate);
		
		return ret;
	}
	#endregion

}
